/*
 * @author=nagebaixiong
 * @version=0.1.0.20230116
 * @createTime=20230116 01:35
 * @lastModifiedTime=20230116 01:35
 * @description=流程控制
 */

#include <iostream>

int main()
{
    int sum = 0;
    int i = 1;

    // for循环求和1到100
    for (i = 1; i <= 100; i++)
    {
        sum += i;
    }
    std::cout << "sum of 1..100 is " << sum << " calc via for" << std::endl;

    // while循环求和1到100
    sum = 0;
    i = 1;
    while (i <= 100)
    {
        sum += i;
        ++i;
    }
    std::cout << "sum of 1..100 is " << sum << " calc via while" << std::endl;

    // do-while循环求和1到100
    sum = 0;
    i = 1;
    do
    {
        sum += i;
        ++i;
    } while (i <= 100);
    std::cout << "sum of 1..100 is " << sum << " calc via do-while" << std::endl;

    // if语句
    int flag = 1;
    if (flag == 0)
    {
        std::cout << "flag == 0" << std::endl;
    } else if (flag < 0) {
        std::cout << "flag < 0" << std::endl;
    } else {
        std::cout << "flag > 0" << std::endl;
    }

    // switch语句
    char grade = 'D';
    switch (grade)
    {
        case 'A':
            std::cout << "grade A" << std::endl;
            break;
        case 'B':
            std::cout << "grade B" << std::endl;
            break;
        case 'C':
            std::cout << "grade C" << std::endl;
            break;
        default:
            std::cout << "match default" << std::endl;
    }

    return 0;
}